package com.ywu.standard.gateway.api;

import com.ywu.api.spi.dto.ApiRouterDto;
import com.ywu.common.result.CommonResult;
import com.ywu.standard.gateway.dto.GatewayRouteRedisDto;
import com.ywu.standard.gateway.service.GatewayRouterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName GatewayRouterApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/1/28 18:14
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/gateway")
@CrossOrigin
public class GatewayRouterApi {
    @Autowired
    private GatewayRouterService gatewayRouterService;

    /**
     * @Author GroundDemo
     * @Description 刷新路由
     * @Date 21:36 2024/2/15
     * @Param []
     * @return com.ywu.blog.common.result.CommonResult<java.lang.Object>
     **/
    @GetMapping("/router.refresh.info")
    public CommonResult<Object> refresh() {
        return gatewayRouterService.refreshRoute();
    }

    /**
    * @Author GroundDemo
    * @Description 重新加载缓存
    * @Date 14:02 2024/3/10
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @GetMapping("/router.reload.info")
    public CommonResult<Object> reloadRoute() {
        return gatewayRouterService.reloadRoute();
    }

    /**
     * @Author GroundDemo
     * @Description 删除路由
     * @Date 21:37 2024/2/15
     * @Param [gatewayRouterDto]
     * @return com.ywu.blog.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/router.delete.info")
    public CommonResult<Object> delete(@RequestBody ApiRouterDto gatewayRouterDto) {
        return gatewayRouterService.deleteRoute(gatewayRouterDto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询API的redis缓存
    * @Date 22:03 2024/2/29
    * @Param [gatewayRouterDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/api.route.redis.cache.info")
    public CommonResult<List<GatewayRouteRedisDto>> apiRouteRedisCacheInfo(@RequestBody ApiRouterDto gatewayRouterDto) {
        return gatewayRouterService.apiRouteRedisCacheInfo(gatewayRouterDto);
    }

    /**
    * @Author GroundDemo
    * @Description 添加路由
    * @Date 22:06 2025/3/20
    * @Param [gatewayRouterDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/add.api.route.for.spi")
    public CommonResult<Object> addApiRouteCacheInfo(@RequestBody ApiRouterDto gatewayRouterDto) {
        return gatewayRouterService.addApiRouteCacheInfo(gatewayRouterDto);
    }
}